"""
@name : 11-12 VerifyPasswd
@author : hj
@projectname: CJH
"""

# • 返回密码的评分等级，及要改进的点：
# • 如 return 3, ['长度小于8', '密码没有由3种以上字符组成']
passwd = input("请输入你要验证的密码：")
lst = list(passwd)
level = 2


#   用户密码复杂度验证 (封装成函数)
def verify():
    checklength()
    checkformat()
    checksubstr()
    print(f"密码等级：{level}")


# • 长度超过8位（必须） +1分
def checklength():
    global level
    if len(passwd) > 8:
        level = level + 1
        # print(f"校验长度成功后后等级为：{level}")
    else:
        print("长度小于8")


# • 包括大、小写字母.数字.其它符号,以上四种至少三种 +1分

def checkformat():
    global level
    inum = []
    ilow = []
    iupp = []
    ipri = []

    for i in lst:
        if i.isdigit():
            inum.append(i)
        elif i.islower():
            ilow.append(i)
        elif i.isupper():
            iupp.append(i)
        elif i.isprintable():
            ipri.append(i)
        else:
            print("啥也不是")

    if f(inum) + f(ilow) + f(iupp) + f(ipri) >= 3:
        level = level + 1
        # print(f"校验字符种类成功后后等级为：{level}")
    else:
        print("密码没有由3种以上字符组成")


def f(n):
    return 1 if len(n) > 0 else 0


# • 不能有长度超过或等于3的子串重复 +1分
def checksubstr():
    global level
    level2 = 0
    for i in range(len(passwd)):
        substr = passwd[i: i + 3]
        subcount = passwd.count(substr)
        if subcount >= 2:
            print(f"{substr}有重复出现 ")
            level2 = 0
            break
        else:
            level2 = 1
    level = level + level2
    # print(f"校验子字符串成功后后等级为：{level}")


verify()

